	<?
	$path = '../Mkart/';
	include($path."common.php");

	//============================================
//	include($path."order_mail.php");
//	include($path."mailsend.php");
	//============================================

	//參數設定

	//公司名稱
	$company = "小烏龜草仔粿" ;

	//管理者信箱

	$query = "select * from kart_manage where (user_auth = 'S' or user_auth = 'O') and user_valid = 'Y' " ;
	$result_list = mysql_query($query);
	while($row_list=mysql_fetch_object($result_list)){
		$back_mail[] = $row_list->user_mail ;
	}

	$admin_mail = "maymaymay621@gmail.com" ;
	//$admin_smtp = "localhost" ;
	//$mail_account = "service@ricepool.com" ;
	//$mail_pwd = "ricepool" ;

	//訂單編號
	$order_no = $oid ;

	//出貨處理日
	$p_date = substr($process_date,0,4) . "/" .  substr($process_date,4,2) . "/"  . substr($process_date,6,2);

	//出貨所需日期
	$n_date = "3";

	//到貨日
	$tmp_date =strtotime($process_date);
	$end_date =  date("Y/m/d",strtotime("+$n_date days",$tmp_date));

	//客戶資訊
	$sql_num = "select * from order_shopper where  order_id = '$order_no' " ;
	$result_num = mysql_query($sql_num) ;
	$row_num=mysql_fetch_object($result_num) ;
	$order_name = $row_num->shopper_name ;
	$order_mail = $row_num->shopper_mail;





	$sql_edit = "select * from  kart_order where order_id = '$oid' " ;
	$result_edit = mysql_query($sql_edit);
	$row_edit=mysql_fetch_object($result_edit);
	$type = $row_edit->order_type;			//付款方式
	$process_date = $row_edit->order_date;		//分期日期
	$process_time = $row_edit->order_time;		//分期時間
	$ord_invoice = $row_edit->order_invoice;	//訂單發票抬頭
	$ord_invoiceno = $row_edit->order_invoiceno;	//訂單統一編號
	$ord_stage = $row_edit->order_stage;		//分期期數
	$amount = $row_edit->order_price ;		//金額

	$ord_dt = substr($process_date,0,4) . "年" .  substr($process_date,4,2) . "月"  . substr($process_date,6,2) . "日&nbsp;&nbsp;" .  substr($process_time,0,2) . ":" .  substr($process_time,2,2) . ":"  . substr($process_time,4,2)  ;

	switch($type){
	////ATM轉帳。
	case "1_1" :
	$order_type .= "<table width=100% border=1 align=center>" ;
	$order_type .= "<tr>" ;
	$order_type .= "<td align=center class=Sky>付款方式</td>" ;
	$order_type .= "<td align=center class=Sky>銀行代號</td>" ;
	$order_type .= "<td align=center class=Sky>帳號</td>" ;
	$order_type .= "<td align=center class=Sky>戶名</td>" ;
	$order_type .= "</tr>" ;
	$order_type .= "<tr>" ;
	$order_type .= "<td align=center>ATM轉帳</td>" ;
	$order_type .= "<td align=center>土地銀行(代號005)青年分行</td>" ;
	$order_type .= "<td align=center>０３８－００５－２２４９１５</td>" ;
	$order_type .= "<td align=center>吳瑞美</td>" ;
	$order_type .= "</tr>" ;
	$order_type .= "</table>" ;
	break;
	////銀行匯款。
	case "1_2" :
	$order_type .= "<table width=100% border=1 align=center>" ;
	$order_type .= "<tr>" ;
	$order_type .= "<td align=center class=Sky>付款方式</td>" ;
	$order_type .= "<td align=center class=Sky >銀行代號</td>" ;
	$order_type .= "<td align=center class=Sky>帳號</td>" ;
	$order_type .= "<td align=center class=Sky>戶名</td>" ;
	$order_type .= "</tr>" ;
	$order_type .= "<tr>" ;
	$order_type .= "<td align=center></td>" ;
	$order_type .= "<td align=center></td>" ;
	$order_type .= "<td align=center></td>" ;
	$order_type .= "<td align=center></td>" ;
	$order_type .= "</tr>" ;
	$order_type .= "</table>" ;
	break;
	////WebAtm。
	case "1_3" :
	$order_type .= "<table width=100% border=1 align=center>" ;
	$order_type .= "<tr>" ;
	$order_type .= "<td align=center class=Sky>付款方式</td>" ;
	$order_type .= "<td align=center class=Sky>付款說明</td>" ;
	$order_type .= "</tr>" ;
	$order_type .= "<tr>" ;
	$order_type .= "<td align=center>WebAtm</td>" ;
	$order_type .= "<td align=left>結帳後點選進入WebATM線上轉帳。使用本付款方式，您需要持有晶片卡讀卡機，任何銀行之晶片金融卡皆可使用。線上轉帳時請您將您的IC晶片金融卡插入讀卡機後，輸入晶片卡密碼，您即可利用金融卡進行線上轉帳交易。(※請先確認讀卡機與電腦連線完成)。本交易由金融卡晶片本身產製驗證碼，傳輸過程均經押碼加密，僅有您的發卡行可解開驗證碼，請安心使用。交易金額與匯款帳號由電腦自動產生。
</td>" ;
	$order_type .= "</tr>" ;
	$order_type .= "</table>" ;
	break;
	////貨到付款。
	case "1_4" :
	$order_type .= "<table width=100% border=1 align=center>" ;
	$order_type .= "<tr>" ;
	$order_type .= "<td align=center class=Sky>付款方式</td>" ;
	$order_type .= "<td align=center class=Sky>付款說明</td>" ;
	$order_type .= "</tr>" ;
	$order_type .= "<tr>" ;
	$order_type .= "<td align=center>貨到付款</td>" ;
	$order_type .= "<td align=center>收貨的同時把款項交給宅配人員。</td>" ;
	$order_type .= "</tr>" ;
	$order_type .= "</table>" ;
	break;
}
	




	//Mail主旨
	$mail_Subject = $order_name."　您好,您在".$company."訂購商品已完成！";

	$m_body .= "<body>";
	$m_body .= "<table width=500 border=0>";
	$m_body .= "<tr>";
	$m_body .= "<td>**************************************************************************************</td>";
	$m_body .= "</tr>";
	$m_body .= "<tr>";
	$m_body .= "<td>請注意︰此郵件是系統自動傳送，請勿直接回覆此郵件。</td>";
	$m_body .= "</tr>";
	$m_body .= "<tr>";
	$m_body .= "<td>**************************************************************************************</td>";
	$m_body .= "</tr>";
	$m_body .= "<tr height=20><td><hr></td></tr>";

	$m_body .= "<tr>";
	$m_body .= "<td>感謝您向".$company."訂購商品，您訂購的商品資訊如下:</td>";
	$m_body .= "</tr>";

	$m_body .= "<tr>";
	$m_body .= "<td>訂單編號：".$order_no."</td>";
	$m_body .= "</tr>";

	$m_body .= "<tr>";
	$m_body .= "<td>";
	
	$m_body .= '<table width="594" border="0" align="center" cellpadding="0" cellspacing="0">';
	$m_body .= '<tr>';
	$m_body .= '<td id="order_process"></td>';
	$m_body .= '</tr>';
	$m_body .= '</table>';

	$m_body .= '<div id=div_print>';
	$m_body .= '<table width=750 border=1 align=center>';
	$m_body .= '<tr>';
	$m_body .= '<td colspan="2" align=center valign="middle" class="title"><h3>訂購確認單</h3></td>';

	$m_body .= '</tr>';
	$m_body .= '<tr>';
	$m_body .= '<td align=right width=20% class="blue">交易單號：</td>';
	$m_body .= '<td align=left>' . $oid . '</td>';
	$m_body .= '</tr>';
	$m_body .= '<tr>';
	$m_body .= '<td align=right class="blue">交易金額：</td>';
	$m_body .= '<td align=left class="Sky">' . $amount . '</td>';
	$m_body .= '</tr>';

	$m_body .= '<tr>';
	$m_body .= '<td align=right class="blue">處理時間：</td>';
	$m_body .= '<td align=left>' . $ord_dt . '</td>';
	$m_body .= '</tr>';
	
	//如果有發票抬頭，就輸出它。
	if($ord_invoice)
	{ 
		$m_body .= '<tr>';
		$m_body .= '<td align=right class="blue">發票抬頭：</td>';
		$m_body .= '<td align=left class="Sky">' . $ord_invoice . '</td>';
		$m_body .= '</tr>';
	}

	//如果有統一編號，就輸出它。
	if($ord_invoiceno)
	{ 
		$m_body .= '<tr>';
		$m_body .= '<td align=right class="blue">統一編號：</td>';
		$m_body .= '<td align=left>' . $ord_invoiceno . '</td>';
		$m_body .= '</tr>';
	} 
	

	$m_body .= '<tr>';
	$m_body .= '<td align=right class="blue">商品明細：</td>';
	$m_body .= '<td align=left>';
	$m_body .= '<table width=100% border=1 align=center cellpadding="6" cellspacing="0">';
	$m_body .= '<td align=left class="Sky" >商品名稱</td>';
	$m_body .= '<td align=center width=20% class="Sky">單價</td>';
	$m_body .= '<td align=center width=20% class="Sky">數量</td>';
	$m_body .= '<td align=center width=20% class="Sky">小計</td>';


	

	$item_totalprice = 0;

	$sql_item = "select * from  order_item where order_id = '$oid' order by order_id" ;
	$result_item = mysql_query($sql_item);
	while($row_item=mysql_fetch_object($result_item))
	{
		$item_no = $row_item->item_id;		//商品編號
		$item_amount = $row_item->item_amount;	//商品購買數量

		$sql_pd = "select * from  product where id = '$item_no' " ;
		$result_pd = mysql_query($sql_pd);
		$row_pd = mysql_fetch_object($result_pd);
		$pd_name = $row_pd->name;		//商品名稱 

		$item_price = $row_pd->price_2 ;
		$item_total = $item_price * $item_amount;

		$item_totalprice += $item_total;
	

		$m_body .= '<tr>';
		$m_body .= '<td align=left>' . $pd_name . '</td>';
		$m_body .= '<td align=center>' . $item_price . '</td>';
		$m_body .= '<td align=center>' . $item_amount . '</td>';
		$m_body .= '<td align=center>' . $item_total . '</td>';
		$m_body .= '</tr>';
	} 
	

	$m_body .= '</table>';
	$m_body .= '</td>';
	$m_body .= '</tr>';

	$m_body .= '<tr>';
	$m_body .= '<td align=right class="blue">交易狀態：</td>';
	$m_body .= '<td align=left class="Sky"><span class="red">交易完成</span></td>';
	$m_body .= '</tr>';

	$m_body .= '<tr>';
	$m_body .= '<td align=right class="blue">付款方式：</td>';
	$m_body .= '<td align=left>' . $order_type . '</td>';
	$m_body .= '</tr>';

	$m_body .= '<tr>';
	$m_body .= '<td align=right class="blue">合計：</td>';
	$m_body .= '<td align=left>小計總合:' . $item_totalprice . ' + 運費:' . ($amount - $item_totalprice) . ' = 交易金額:<span >' . $amount . '</span></td>';
	$m_body .= '</tr>';

	$m_body .= '</table>';


	$m_body .= "</td>";
	$m_body .= "</tr>";
	$m_body .= "<tr>";
	$m_body .= "<td>您訂購的商品廠商已於 ".$p_date." 為您處理 ，預計 ".$n_date." 天左右出貨，預估到貨時間為 ".$end_date." 左右，請您耐心等候！</td>";
	$m_body .= "</tr>";

	//$m_body .= "<tr height=20><td><hr></td></tr>";
	//$m_body .= "<tr height=20><td><hr></td></tr>";

	$m_body .= "<tr>";
	$m_body .= "<td>**************************************************************************************</td>";
	$m_body .= "</tr>";
	$m_body .= "<tr>";
	$m_body .= "<td>請注意︰此郵件是系統自動傳送，請勿直接回覆此郵件。</td>";
	$m_body .= "</tr>";
	$m_body .= "<tr>";
	$m_body .= "<td>**************************************************************************************</td>";
	$m_body .= "</tr>";

	$m_body .= "</table>";

	$m_body .= "</body>";
//$m_body .= var_dump($result_item);
	?>
